Questions
5 of 30
1What is the purpose of the transform property in CSS?
2What are the different types of CSS transformations?
3What does transform: translate() do?
4What is the difference between translateX() and translateY()?
5How does rotate() work in CSS?
6What is the unit used in rotation?
7What is the difference between scale() and scaleX(), scaleY()?
8What happens when you use negative values in scale()?
9What does the skew() function do?
10Can you combine multiple transform functions together? How? What is the use of the transform-origin property?
11What is the default transform-origin value?
12How does changing transform-origin affect rotation or scaling?
13What is the difference between translate() and using position or margin for movement?
14What is the difference between 2D and 3D transformations?
15What is the difference between 2D and 3D transformations?
16How do you apply a 3D rotation using CSS?
17How do you apply a 3D rotation using CSS?
18What are perspective and perspective-origin in 3D transforms? What is the purpose of transform-style: preserve-3d?
19What is the use of matrix() in CSS transforms?
20What’s the difference between matrix() and matrix3d()?
21How can you center an element using transform and translate()?
22What is the transition property in CSS used for?
23What are the four main components of a transition?
24What does transition-duration specify?
25What are the common timing function values (e.g., ease, linear, ease-in)?
26What is the shorthand syntax for transition?
27Can multiple CSS properties be transitioned simultaneously? How does transition differ from animation in CSS?
28Can you apply a transition to an element’s pseudo-class (like :hover)?
29Can transitions be triggered by JavaScript?
30What happens if transition-duration is set to 0s?
05 / 30

How does rotate() work in CSS?

Understanding the rotate() Function in CSS

The rotate() function in CSS is part of the transform property. It allows you to rotate an element around a fixed point (by default, the element’s center) in either 2D or 3D space. The rotation is defined using an angle, such as degrees (deg), radians (rad), or turns (turn).

Syntax and Variations
  1. 1

    rotate(angle) — rotates an element clockwise by the given angle in 2D space.

  2. 2

    rotateX(angle) — rotates an element around the X-axis (3D rotation).

  3. 3

    rotateY(angle) — rotates an element around the Y-axis (3D rotation).

  4. 4

    rotateZ(angle) — rotates an element around the Z-axis (similar to rotate() in 2D).

Example: Basic 2D Rotation

In this example, the box rotates 45 degrees clockwise when hovered. The transition property ensures the rotation happens smoothly.

Example: Combining rotate() with Other Transforms

Here, the element not only rotates but also scales and moves slightly upward to create a dynamic hover animation. This combination leverages GPU acceleration for smoother motion.

Best Practices
  1. 1

    Use rotate() for visually appealing animations like spinning icons or tilted cards.

  2. 2

    Pair with transition or animation for smooth effects.

  3. 3

    Be aware of the transform-origin property, which defines the point around which the element rotates (default is center).

  4. 4

    Combine rotate() with other transforms for layered motion effects.